package util;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

public class GetsTablefieldsUtil {

    public static Vector<String> getAllcolumns(String tableName) {
        Vector<String> strings=new Vector<>();
        try (Connection connection = DBUtil.getConn()) {
            DatabaseMetaData metaData = connection.getMetaData();
            ResultSet columns = metaData.getColumns(null, null, tableName, null);
            int i=0;
            while (columns.next()) {
                String columnName = columns.getString("COLUMN_NAME");
                strings.add(columnName);
                String columnType = columns.getString("TYPE_NAME");
                int columnSize = columns.getInt("COLUMN_SIZE");
                boolean isNullable = columns.getBoolean("NULLABLE");
            }
            return strings;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static Vector<String> getAllDataType(String tableName) {
        Vector<String> getAllDataType=new Vector<>();
        try (Connection connection = DBUtil.getConn()) {
            DatabaseMetaData metaData = connection.getMetaData();
            ResultSet columns = metaData.getColumns(null, null, tableName, null);
            while (columns.next()) {
                String columnType = columns.getString("TYPE_NAME");
                getAllDataType.add(columnType);
            }
            return getAllDataType;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }


    public static void main(String[] args) {
        Vector<String> personnels = GetsTablefieldsUtil.getAllcolumns("personnel");

    }
}
